(function($){
	
	$.fn.selInit = function(){return $(this).html("<option value=''>\u8bf7\u9009\u62e9</option>");};
	
	$.linkage = function(jsonDatas,links,selectd,init,text){
		if(init == true){
			for(var i= 0;i < links.length; i++){
				$("#" + links[i]).selInit();
			}
			
		}
		$.each(links,function(i,linkValue){
			$("#" + linkValue).change(function(){
				for(var j = i + 1; j < links.length; j++){
					$("#" + links[j]).selInit();
				}
				if(i == links.length - 1){
					return false;
				}
				var data = jsonDatas;
				for(var ii = 0; ii < i + 1; ii++){
					var text = $("#" + links[ii]  +" option:selected").text();
					if(text=="\u8bf7\u9009\u62e9"){
						return false;
					}
					$.each(data,function(key,linkValue){
						if(linkValue.name == text){
							data = linkValue.childs;
							return false;
						}
					});
				}
				
				$.each(data,function(key,value){
					if(selectd[i+1] == value.value){
						$("#" + links[i+1]).append("<option value='" + value.value + "' selected='selected'>" + value.name + "</option>");
						$("#" + links[i+1]).change();
					}else{
						$("#" + links[i+1]).append("<option value='" + value.value + "'>" + value.name + "</option>");
					}
					
				});
			});
		});
		$.each(jsonDatas,function(key,data){
			if(selectd[0] == data.value){
				$("#" + links[0]).append("<option value='" + data.value + "' selected='selected'>" + data.name + "</option>");
				$("#" + links[0]).change();
			}else{
				$("#" + links[0]).append("<option value='" + data.value + "'>" + data.name + "</option>");
			}
		});
	};
})(jQuery);